package com.example.lj.uav.view;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Spinner;
import android.widget.TextView;

import com.example.lj.uav.MyApplication;
import com.example.lj.uav.R;
import com.example.lj.uav.adapter.SpinnerDropDownAdapter;
import com.example.lj.uav.utils.OnUIUtils;
import com.example.lj.uav.view.base.BaseActivity;
import com.example.lj.uav.widget.ChannelLayout;
import com.example.lj.uav.widget.ChannelView;
import com.example.lj.uav.widget.DragRectView;

import dji.common.airlink.ChannelInterference;
import dji.common.error.DJIError;
import dji.common.util.CommonCallbacks;
import dji.sdk.airlink.AirLink;
import dji.sdk.airlink.LightbridgeLink;

public class TestActivity extends BaseActivity implements View.OnClickListener {

    private Context context;
    private static Handler mHandler;
    private Spinner sp;
    private SpinnerDropDownAdapter adapter;
    private String[] list = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"};
    private TextView count;
    private TextView test;
    private ChannelView channelView;
    private DragRectView view;
    //    private BatteryView batteryView;
    private ChannelView channel;
    private DragRectView drag;
    private ChannelLayout channelLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        context = this;
//        batteryView = findViewById(R.id.bv);
//        batteryView.setPower(50);
        channelLayout = (ChannelLayout) findViewById(R.id.channel_layout);
        channelLayout.setOnChannelSelectedListener(new ChannelLayout.OnChannelSelectedListener() {
            @Override
            public void OnChannelSelected(int p) {
                OnUIUtils.setToast(p + "");
            }
        });

        AirLink airLink = MyApplication.getAirLinkInstance();
        if (airLink != null) {
            LightbridgeLink lightbridgeLink = airLink.getLightbridgeLink();
            lightbridgeLink.setChannelInterferenceCallback(new LightbridgeLink.ChannelInterferenceCallback() {
                @Override
                public void onResult(ChannelInterference[] cnl) {
                    float[] c = new float[cnl.length];
                    float[] p = new float[cnl.length];
                    for (int i = 0; i < cnl.length; i++) {
                        c[i] = cnl[i].getChannel();
                        p[i] = cnl[i].getPower();
                    }
                    channelLayout.setupValue(c, p);
                    channelLayout.setVisibility(View.VISIBLE);
                }
            });
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

        }
    }

}
